import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class PLONK {
    private StringTokenizer st;
    private void run() throws Exception {
        BufferedReader bf = new BufferedReader( new InputStreamReader ( System.in ) );
        st = new StringTokenizer(bf.readLine());
        int tcase = Integer.parseInt(st.nextToken());
        while(tcase-->0){
             st = new StringTokenizer(bf.readLine());
             int n = Integer.parseInt(st.nextToken());
             int x [] = new int [n]; int y [] = new int [n];
             int sx [] = new int[n]; int sy [] = new int [n];
             int cx [] = new int[n]; int cy [] = new int[n];
             for(int i=0;i<n;++i){
                 st = new StringTokenizer(bf.readLine());
                 x[i] = Integer.parseInt(st.nextToken());
                 y[i] = Integer.parseInt(st.nextToken());
                 sx[i] = x[i]; sy[i] = y[i];
             }
             Arrays.sort(sx); Arrays.sort(sy);
             for(int i=0;i<n;++i){
                 if(i==0) {
                    cx[i] = sx[i]; cy[i] = sy[i];
                 }
                 else {
                    cx[i] = cx[i-1]+sx[i];
                    cy[i] = cy[i-1]+sy[i];
                 }
             }
             int mn = Integer.MAX_VALUE;
             for(int i=0;i<n;++i){
                 int ix = Arrays.binarySearch(sx,x[i]);
                 int iy = Arrays.binarySearch(sy,y[i]);
                 int res = cx[n-1]-cx[ix]-(n-1-ix)*x[i] + (ix+1)*x[i]-cx[ix] +
                           cy[n-1]-cy[iy]-(n-1-iy)*y[i] + (iy+1)*y[i]-cy[iy];
                 mn = Math.min(mn,res);
             }
             System.out.println(mn);
        }
    }
    public static void main ( String [] Args ) throws Exception {
        new PLONK().run();
    }
}